const removeChar = (str, char) => {
  return str.replace(char, '');
};

const removeDashes = (str) => {
  return removeChar(str, '-');
};

const isNumber = (str) => {
  let out = true;
  for (let i = 0; out && i < str.length; i++) {
    out &= (str[i] <= '9' && str[i] >= '0');
  }
  return out;
};

const toFriendlyLocation = (str) => {
  let floor = str[0];
  let section = str[1];
  let rack = str.substr(2, 2);
  let face = str[4];
  let cell = str.substr(5, 2);
  return `${floor} 层 ${section} 区 ${rack} 架 ${face} 面 ${cell[0]}-${cell[1]} 层`;
};

module.exports = {
  removeChar: removeChar,
  removeDashes: removeDashes,
  isNumber: isNumber,
  toFriendlyLocation: toFriendlyLocation,
};
